home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / NewsTicker.sit / NewsTicker / source code / Extractors / TickerCheckWebs.cp < prev    next >
Text File  |  1997-06-21  |  5KB  |  170 lines

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    NewsTicker, my Hack for 1997
  4. #
  5. #    TickerCheckWebs.cp    -    Check to see if web pages have changed.
  6. #
  7. ------------------------------------------------------------------------------*/
  8.  
  9. #include "TickerGlobals.h"        /* bring in all the #defines for NewsTicker */
  10. #include "TickerCheckWebs.h"
  11. #include "TickerReadHeadlines.h"
  12. #include "TickerWindowHandler.h"
  13. #include "HTMLExtractor.h"
  14.  
  15. // update every 15 minutes
  16.  
  17. #define        kWebCheckDuration 900
  18.  
  19. // Globals for Web Checking
  20.  
  21. static unsigned long gWebCheckTime = 0;
  22. static short nextEntryToCheck = 0;
  23.  
  24. //
  25. // For any web page (passed as address, not URL) get the last modified date
  26. //
  27. void GetModifiedDate( sMyDataPtr    gGlobalsPtr, char* thename, Str31 LastModStr )
  28. {
  29.     Boolean        DidAny = false;
  30.     HTMLExtractor* thehandler;
  31.     
  32.     thehandler = new HTMLExtractor(thename, 0, gGlobalsPtr);
  33.     
  34.     thehandler->ReadLastModified();
  35.     thehandler->GetLastModified(LastModStr);
  36.     delete thehandler;
  37.             
  38.     InitCursor();
  39. }
  40.  
  41. void UpdateChangedWebs(sMyDataPtr    gGlobalsPtr)
  42. {
  43.     short    index;
  44.     short    destindex;
  45.     Str255    tempstr;
  46.     
  47.     // Delete all entries with cicnResID = kWebIconID
  48.     destindex = 0;
  49.     for (index = 0; index < gGlobalsPtr->MsgCount; index++)
  50.     {
  51.         if (gGlobalsPtr->theHeadlines[index].cicnResID!=kWebIconID)    //don't delete it
  52.         {
  53.             if (index!=destindex)    //copy down if we need to
  54.             {
  55.                 gGlobalsPtr->theHeadlines[destindex] = gGlobalsPtr->theHeadlines[index];
  56.             }
  57.             destindex++;
  58.         }
  59.     }
  60.     gGlobalsPtr->MsgCount = destindex;
  61.     
  62.     // Now copy the entries we've changed accumulated out
  63.     for (index = 0; index<numWebPages; index++)    // copy the entries off
  64.     {
  65.         if (gThePrefs.WebPageDisplay[index]&&(gGlobalsPtr->MsgCount<maxHeadlines))
  66.         {    //add it!
  67.             PLstrcpy(tempstr, "\phttp://");    //form the URL
  68.             PLstrcat(tempstr, gThePrefs.WebPageAddress[index]);
  69.             
  70.             destindex = gGlobalsPtr->MsgCount;
  71.             PLstrcpy(gGlobalsPtr->theHeadlines[destindex].Subject, 
  72.                 gThePrefs.WebPageAddress[index]);
  73.             PLstrcpy(gGlobalsPtr->theHeadlines[destindex].URL, tempstr);
  74.             gGlobalsPtr->theHeadlines[destindex].cicnResID = kWebIconID;
  75.             
  76.             gGlobalsPtr->MsgCount++;
  77.         }
  78.     }
  79. }
  80.  
  81. void UpdateAWebEntry(sMyDataPtr    gGlobalsPtr, short whichmsg)
  82. {
  83.     short    index, index2;
  84.     
  85.     for (index = 0; index<numWebPages; index++)
  86.     {
  87.         if (gThePrefs.WebPageDisplay[index])
  88.         {
  89.             if (EqualString(gThePrefs.WebPageAddress[index],
  90.                     gGlobalsPtr->theHeadlines[whichmsg].Subject, false, false))
  91.             {
  92.                 LaunchURL(gGlobalsPtr->theHeadlines[whichmsg].URL);
  93.                 
  94.                 gThePrefs.WebPageDisplay[index] = false;    //OK, we've read this
  95.                 
  96.                 gGlobalsPtr->MsgCount--;
  97.                 for (index2 = whichmsg; index2<gGlobalsPtr->MsgCount; index2++)    //Remove us from the scrolling list
  98.                 {
  99.                     gGlobalsPtr->theHeadlines[index2] = gGlobalsPtr->theHeadlines[index2+1];
  100.                 }
  101.                 
  102.                 CalcOffsets(gGlobalsPtr);
  103.                 return;
  104.             }
  105.         }
  106.     }
  107. }
  108.  
  109. void CheckChangedWebPages(sMyDataPtr    gGlobalsPtr)
  110. {
  111.     unsigned long    now;
  112.     Str31            newModifiedTime;
  113.     Str255            tempstr;
  114.     Boolean            NewDoDisplay;
  115.     short            index2;
  116.     short            whichitem;
  117.     
  118.     GetDateTime(&now);
  119.     
  120.     if (!gWebCheckTime)    //first call, don't do anything
  121.     {
  122.         gWebCheckTime = now + kWebCheckDuration;
  123.         return;
  124.     }
  125.     
  126.     if (now<gWebCheckTime)    //time to check the next entry?
  127.         return;
  128.     gWebCheckTime = now + kWebCheckDuration;
  129.     
  130.     nextEntryToCheck++;
  131.     if (nextEntryToCheck>=numWebPages)
  132.         nextEntryToCheck = 0;
  133.             
  134.     if (gThePrefs.WebPageAddress[nextEntryToCheck][0])    //Only check those entries that have an address
  135.     {
  136.         PLstrcpy(tempstr, gThePrefs.WebPageAddress[nextEntryToCheck]);
  137.         tempstr[tempstr[0]+1] = 0;    //make it a nice c string
  138.         
  139.         GetModifiedDate( gGlobalsPtr, (char*)(&tempstr[1]), newModifiedTime); //get the modified time
  140.         
  141.         if (!newModifiedTime[0])    //no date
  142.             NewDoDisplay = true;
  143.             else
  144.             {
  145.                 NewDoDisplay = !EqualString(newModifiedTime, gThePrefs.WebPageLastDate[nextEntryToCheck], false, false);
  146.                 PLstrcpy(gThePrefs.WebPageLastDate[nextEntryToCheck], newModifiedTime);
  147.             }
  148.         
  149.         if (NewDoDisplay && (!gThePrefs.WebPageDisplay[nextEntryToCheck]))    //need to start displaying it?
  150.         {
  151.             gThePrefs.WebPageDisplay[nextEntryToCheck] = true;
  152.             
  153.             for (index2 = gGlobalsPtr->MsgCount; index2>0; index2--)    //Open up entry 0
  154.             {
  155.                 gGlobalsPtr->theHeadlines[index2] = gGlobalsPtr->theHeadlines[index2-1];
  156.             }
  157.             gGlobalsPtr->MsgCount++;                            //we're going to add us at the start
  158.  
  159.             PLstrcpy(tempstr, "\phttp://");    //form the URL
  160.             PLstrcat(tempstr, gThePrefs.WebPageAddress[nextEntryToCheck]);
  161.             
  162.             PLstrcpy(gGlobalsPtr->theHeadlines[0].Subject, 
  163.                 gThePrefs.WebPageAddress[nextEntryToCheck]);
  164.             PLstrcpy(gGlobalsPtr->theHeadlines[0].URL, tempstr);
  165.             gGlobalsPtr->theHeadlines[0].cicnResID = kWebIconID;
  166.             CalcOffsets(gGlobalsPtr);
  167.         }
  168.     }
  169. }
  170.